import hashlib
import uuid
from django.conf import settings


def md5(string):
    """ MD5加密 """
    hash_object = hashlib.md5(settings.SECRET_KEY.encode('utf-8'))
    hash_object.update(string.encode('utf-8'))
    return hash_object.hexdigest()

def uid(string):#用于markdown 上传图片的KEY 的命名
    data = "{}-{}".format(str(uuid.uuid4()), string)
    return md5(data)




if __name__=='__main__':
    print(md5('123'))
    #django.core.exceptions.
    # ImproperlyConfigured: Requested setting SECRET_KEY,
    # but settings are not configured. You must either define the environment
    # variable DJANGO_SETTINGS_MODULE or call settings.configure() before accessing settings.
    print(type(md5('123')))